package com.twh.www.service.login;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录策略工厂类
 */
@Component
public class LoginStrategyFactory {
    private final Map<String, LoginStrategy> strategyMap = new HashMap<>();

    @Autowired
    public LoginStrategyFactory(LoginStrategy... strategies) {
        for (LoginStrategy strategy : strategies) {
            strategyMap.put(strategy.getLoginType(), strategy);
        }
    }

    /**
     * 根据登录类型获取对应的登录策略
     * @param loginType 登录类型
     * @return 登录策略实现类
     */
    public LoginStrategy getStrategy(String loginType) {
        return strategyMap.get(loginType);
    }
} 